import '../base_model.dart';

/// 基础实体
class UserModel extends BaseModel {
  int uid;
  int usex;
  String uname;
  int utype;
  int ulevel;
  int ubirthday;
  int ustatus;
  String usign;
  String uhead;
  String ucover;
  int isinvite;
  String openid;
  String type;
  AccountModel account;
  int ismkxq;
  AuthTokenModel authToken;
  String mkxqaes;
  String accessToken;
  int viewKeywords;
  int isCanLogOff;
  int regDays;
  int isclose;
  int isDevice;
  UserModel.fromJson(Map<String, dynamic> data) : super.fromJson(data) {
    uid = data['uid'] ?? 0;
    usex = data['usex'] ?? 0;
    uname = data['uname'] ?? '登录后积分赚不停';
    utype = data['utype'] ?? 0;
    ulevel = data['ulevel'] ?? 0;
    ubirthday = data['ubirthday'] ?? 0;
    ustatus = data['ustatus'] ?? 0;
    usign = data['usign'] ?? '-';
    uhead = data['uhead'] ?? '-';
    ucover = data['ucover'] ?? '-';
    isinvite = data['isinvite'] ?? 0;
    openid = data['openid'] ?? '-';
    type = data['type'] ?? 'device';
    account = AccountModel.fromJson(data['account'] ?? {});
    ismkxq = data['ismkxq'] ?? 0;
    authToken = AuthTokenModel.fromJson(data['auth_token'] ?? {});
    mkxqaes = data['mkxqaes'] ?? '';
    accessToken = data['access_token'] ?? '';
    viewKeywords = data['view_keywords'] ?? 0;
    isCanLogOff = data['is_can_logoff'] ?? 0;
    regDays = data['regdays'] ?? 0;
    isclose = data['isclose'] ?? 0;
    isDevice = data['is_device'] ?? 0;
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      'uid': uid,
      'usex': usex,
      'uname': uname,
      'utype': utype,
      'ulevel': ulevel,
      'ubirthday': ubirthday,
      'ustatus': ustatus,
      'usign': usign,
      'uhead': uhead,
      'ucover': ucover,
      'isinvite': isinvite,
      'openid': openid,
      'type': type,
      'account': account,
      'ismkxq': ismkxq,
      'authToken': authToken,
      'mkxqaes': mkxqaes,
      'accessToken': accessToken,
      'viewKeywords': viewKeywords,
      'isCanLogOff': isCanLogOff,
      'regDays': regDays,
      'isclose': isclose,
      'isDevice': isDevice
    };
  }
}

class AccountModel extends BaseModel {
  int exp;
  int gold;
  int coins;
  int ecyCoin;
  int ecyCoinIos;
  AccountModel.fromJson(Map<String, dynamic> data) : super.fromJson(data) {
    exp = data['exp'] ?? 0;
    gold = data['gold'] ?? 0;
    coins = data['coins'] ?? 0;
    ecyCoin = data['ecy_coin'] ?? 0;
    ecyCoinIos = data['ecy_coin_ios'] ?? 0;
  }
  @override
  Map<String, dynamic> toJson() {
    return {
      'exp': exp,
      'gold': gold,
      'coins': coins,
      'ecyCoin': ecyCoin,
      'ecyCoinIos': ecyCoinIos,
    };
  }
}

class AuthTokenModel extends BaseModel {
  int expiry;
  int appid;
  String authcode;
  String imageDomain;
  String imageLimit;

  AuthTokenModel.fromJson(Map<String, dynamic> data) : super.fromJson(data) {
    expiry = data['expiry'] ?? 0;
    appid = int.parse(data['appid'] ?? '0');
    authcode = data['authcode'] ?? '';
    imageDomain = data['imagedomain'] ?? '';
    imageLimit = data['imagelimit'] ?? '';
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      'expiry': expiry,
      'appid': appid,
      'authcode': authcode,
      'imageDomain': imageDomain,
      'imageLimit': imageLimit
    };
  }
}